/******************************************************
 *                                                     
 *              Score System               
 *                                                     
 *******************************************************/

/**
 * Context.java
 *
 * 用户管理的Context类
 *
 * @author sundy
 * @version 0.0.1
 * lastModified 2011-01-01
 */

package com.sundy.core;

import java.util.List;

import com.sundy.daosupport.TeacherTblDAO;
import com.sundy.service.TeacherTbl;

public class Context {
	private TeacherTbl currentUser;

	public boolean login(String name, String password) {
		TeacherTblDAO dao = TeacherTblDAO
				.getFromApplicationContext(Common.applicationContext);
		List<TeacherTbl> list = dao.findByName(name);
		if (list == null || list.isEmpty())
			return false;
		else {
			if (list.get(0).getPassword().equals(password)) {
				this.currentUser = list.get(0);
				return true;
			}
			return false;
		}
	}

	public TeacherTbl getCurrentUser() {
		return currentUser;
	}

	public boolean isLogin() {
		return currentUser != null;
	}

	public void logout() {
		currentUser = null;
	}
}
